package com.mwy.springbootrabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    //声明一个交换机（这里声明的主题交换机）
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic_exchange");
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout_exchange");
    }

    //声明一个队列
    @Bean
    public Queue queue(){
        return new Queue("topic");
    }

    @Bean
    public Queue queueFanout01(){
        return new Queue("fanout01");
    }

    @Bean
    public Queue queueFanout02(){
        return new Queue("fanout02");
    }

    //将队列和交换机进行绑定
    @Bean
    public Binding binding(){
        //绑定哪个队列，到哪个交换机上，用什么routingKey
        return BindingBuilder.bind(queue()).to(topicExchange()).with("*.orange.#");
    }

    @Bean
    public Binding bindingFanout01(){
        return BindingBuilder.bind(queueFanout01()).to(fanoutExchange());
    }

    @Bean
    public Binding bindingFanout02(){
        return BindingBuilder.bind(queueFanout02()).to(fanoutExchange());
    }
}
